<%@page import="java.util.Iterator"%>
<%@page import="model.Sale"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="persistence.sale.SalePersistFactory"%>
<%@page import="persistence.sale.SaleDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>SaleList - appBuy</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="css/coin-slider.css" />
        <script type="text/javascript" src="js/cufon-yui.js"></script>
        <script type="text/javascript" src="js/droid_sans_400-droid_sans_700.font.js"></script>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
        <script type="text/javascript" src="js/coin-slider.min.js"></script>
    </head>
    <%@ include file="userBar.jsp" %>
    <%@ include file="topBar.jsp" %>
    <%@ include file="sideBar.jsp" %>


    <div class="content">
        <div class="content_resize">
            <div class="mainbar">
                <div class="article">
                    <%
                                ServletConfig conf = getServletConfig();
                                ServletContext context = conf.getServletContext();
                                String persistenceMechanism = context.getInitParameter("persistenceMechanism");
                                SaleDAO persistenceManager = SalePersistFactory.getSaleDAO(persistenceMechanism);
                                Map<String, Sale> saleMap = new HashMap<String, Sale>();
                                persistenceManager.readAllSales(saleMap);
                                if (saleMap.size() == 0) {
                    %>
                    <h1 align="center"><br>No existen ventas</h1>
                        <%} else {%>

                    <br><h2><span>Listado de ventas!</span></h2><br>
                    <%
                                        Iterator ventas = saleMap.entrySet().iterator();
                                        while (ventas.hasNext()) {
                                            java.util.Map.Entry e = (java.util.Map.Entry) ventas.next();
                                            request.setAttribute("sale", (model.Sale) e.getValue());
                    %>
                    <jsp:useBean id="sale" scope="request" class="model.Sale" />

                    <p class="infopost">Añadida <span class="date">el <jsp:getProperty name="sale" property="fecha" /></span> por <a href="/Appbuy/FrontController?form=readUserServlet&userName=<jsp:getProperty name="sale" property="usuario" />"><jsp:getProperty name="sale" property="usuario"/></a><a href="#" class="com"><b>Precio: <span><jsp:getProperty name="sale" property="importe" />€</span></b></a></p>
                    <div class="clr"></div>
                    <div class="post_content"><br>
                        <b>· Identificador:</b> <jsp:getProperty name="sale" property="id" /><br><br>
                        <b>· Producto:</b> <jsp:getProperty name="sale" property="productos" /><br><br>
                        <b>· Método de pago:</b> <jsp:getProperty name="sale" property="pago" /><br><br>
                        <b>· Dirección de envío:</b> <jsp:getProperty name="sale" property="direccion" /><br><br>
                    </div>
                    <div class="clr"></div>
                    <%}
                                }%>
                </div>
            </div>
            <div class="clr"></div>
        </div>
    </div>
    <%@ include file="bottomBar.jsp" %>
</html>